const https = require('https');
const cheerio = require('cheerio');

//爬取某个网页的img的src

https.get('https://www.bilibili.com', (res) => {
  res.setEncoding('utf8');
  let rawData = '';
  const imgArr = [];
  res.on('data', (chunk) => {
    rawData += chunk;
  });
  res.on('end', () => {
    const $ = cheerio.load(rawData);
    $('img').each((index,item) => {
      imgArr.push($(item).attr('src'));
    })
    console.log(imgArr);
  });
}).on('error', (e) => {
  console.error(`Got error: ${e.message}`);
});
